# Contributor: Daniel Santana <daniel@santana.tech>
# Maintainer: Daniel Santana <daniel@santana.tech>
pkgname=proot
pkgver=5.4.0
pkgrel=0
pkgdesc="User-space implementation of chroot, mount --bind, and binfmt_misc"
url="https://proot-me.github.io"
arch="aarch64 armhf armv7 x86 x86_64"
license="GPL-2.0-or-later"
checkdepends="bash coreutils grep lzop mcookie python3 strace"
makedepends="
	bsd-compat-headers
	libarchive-dev
	linux-headers
	py3-docutils
	talloc-dev
	talloc-static
	uthash-dev
	"
subpackages="$pkgname-doc $pkgname-static"
source="https://github.com/proot-me/proot/archive/v$pkgver/proot-$pkgver.tar.gz
	tests-musl-compat.patch
	"
options="!check"  # FIXME: several tests are failing

prepare() {
	default_prepare
	cp -r src src-static
}

build() {
	make -C src proot VERSION=$pkgver
	make -C src-static proot VERSION=$pkgver LDFLAGS="$LDFLAGS -static -ltalloc"
	make -C doc proot/man.1
}

check() {
	ln -sfv /usr/bin/python3 python
	PATH="$PATH:$PWD" make -C test
}

package() {
	install -Dm 0755 ./src/proot "$pkgdir"/usr/bin/proot
	install -Dm 0644 ./doc/proot/man.1 "$pkgdir"/usr/share/man/man1/proot.1
}

static() {
	pkgdesc="$pkgdesc (built as static binary)"

	install -Dm 0755 "$builddir"/src-static/proot "$subpkgdir"/usr/bin/proot.static
}

sha512sums="
c4d7b7428758c0d8f6a89ecaa01d1d7d5d9663a84b7e730e8160bc2a2385a7e278589f5dd86f5cd4f8e0736f09b3097b9efea7814096fd2d28e6032435b9ee63  proot-5.4.0.tar.gz
d09de6d776072e9991abd04e294e6d36bd1634b9e972294a112526ebf3f63e919d01755de1ecd7253d614b41b07fe6882df8787c638b8576bcf2555abcafa466  tests-musl-compat.patch
"
